import os;
import sys;
import platform;

sysstr = platform.system()
skip_make = False

if sysstr == "Windows":
	skip_make = True

if not skip_make:
	make_cmd = "make"
	print(make_cmd)
	result = os.system(make_cmd)
	if result != 0:
		exit(result)

scene_idx = 0
if len(sys.argv) > 1:
	if sys.argv[1] == "1":
		scene_idx = 1
	elif sys.argv[1] == "2":
		scene_idx = 2
	elif sys.argv[1] == '3':
		scene_idx = 3
	elif sys.argv[1] == '4':
		scene_idx = 4
run_cmd = "./scenes/scene01/scene01.xml"
image_path = "./scenes/scene01/scene01.bmp"

if scene_idx == 1:
	run_cmd = "./scenes/scene02/scene02.xml"
	image_path = "./scenes/scene02/scene02.bmp"
elif scene_idx == 2:
	run_cmd = "./scenes/mitsuba/mitsuba.xml"
	image_path = "./scenes/mitsuba/mitsuba.bmp"
elif scene_idx == 3:
	run_cmd = "./scenes/shader_ball/shader_ball.xml"
	image_path = "./scenes/shader_ball/shader_ball.bmp"
elif scene_idx == 4:
	run_cmd = "./scenes/killeroo/killeroo.xml"
	image_path = "./scenes/killeroo/killeroo.bmp"
run_cmd += " " + image_path
if sysstr == "Windows":
	run_cmd = R'bin\RayTracer.exe ' + run_cmd
else:
	run_cmd = "time ./bin/RayTracer " + run_cmd
print(run_cmd)
result = os.system(run_cmd)
if result != 0:
	exit(result)
if sysstr == "Windows":
	show_result_cmd = image_path.replace('/', '\\')
else:
	show_result_cmd = "open " + image_path
#print(show_result_cmd)
os.system(show_result_cmd)
